<template>
  <div class="content-center">
    <div class="content-cotainer border-box">
      <div class="centent-title">
        <span style="font-size: medium ">添加模板分类</span>
      </div>
      <div style="margin: 10px;">
        <el-form :label-position="labelPosition" label-width="90px" size="small" :model="docForm">
          <div>
            <el-form-item label="文书标题">
              <el-input v-model="docForm.sysDocuTitle" placeholder="请输入文书标题"></el-input>
            </el-form-item>
            <el-form-item label="文书描述">
              <el-input v-model="docForm.sysDocuDsc" placeholder="请输入文书描述"></el-input>
            </el-form-item>
            <el-form-item label="文书类型">
              <el-select v-model="docForm.sysDocuType"  placeholder="请选择文书类型">
                <el-option label="可修改" value="20"></el-option>
                <el-option label="不可修改" value="10"></el-option>
              </el-select>
            </el-form-item>
          </div>  
          <div style="text-align: center">
            <el-button type="primary" style="width:200px" @click="submitForm()">提交</el-button>
          </div>
        </el-form>
    </div>
  </div>
  </div>
</template>

<script>
import axios from "axios"
export default {
  data() {
    return {
      labelPosition: 'right',
      docForm: {
        sysDocuTitle:'',
        sysDocuDsc:'',
        sysDocuType:''
      }
    }
  },
  mounted() {
    let flag = this.$route.query.flag;
    if(flag=="upd"){
      let item = this.$route.query.item;
      let docForm = {
        sysDocuTitle: item.label,
        sysDocuDsc: item.sysDocuDsc,
        sysDocuType: item.sysDocuType
      };
      this.docForm = docForm;
    }
  },
  methods: {
    submitForm(){
      const loading = this.$loading({
        lock: true,
        text: '正在提交',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      let item = this.$route.query.item;
      let flag = this.$route.query.flag;
      if(flag=="add"){
        let params = {
          parentDocuId: item.id,
          sysDocuTitle: this.docForm.sysDocuTitle,
          sysDocuDsc: this.docForm.sysDocuDsc,
          isRootNode: false,
          sysDocuType: this.docForm.sysDocuType,
          rcrdCrtpsnId:'0001',
          rcrdCrtpsnNm:'管理员',
          rcrdUptpsnId:'0001',
          rcrdUptpsnNm:'管理员'
        };
        axios.post('http://localhost:7111/fileTmpl/addTOesSysDoc', params).then((response) => {
          if(response.data.resultCode=="200"){
            this.$message({
              type: 'success',
              message: response.data.resultMsg
            });
            loading.close();
            this.$router.push({name:'auditWritTemplate'})
          }else{
            this.$message.error(response.data.resultMsg);
          }
        }).catch((response) => {
          console.log(response)
        })
      }else{
        let params = {
          sysDocuId: item.id,
          sysDocuTitle: this.docForm.sysDocuTitle,
          sysDocuDsc: this.docForm.sysDocuDsc,
          isRootNode: false,
          sysDocuType: this.docForm.sysDocuType,
          rcrdCrtpsnId:'0001',
          rcrdCrtpsnNm:'管理员',
          rcrdUptpsnId:'0001',
          rcrdUptpsnNm:'管理员'
        };
        axios.post('http://localhost:7111/fileTmpl/updateTOesSysDoc', params).then((response) => {
          if(response.data.resultCode=="200"){
            this.$message({
              type: 'success',
              message: response.data.resultMsg
            });
            loading.close();
            this.$router.push({name:'auditWritTemplate'})
          }else{
            this.$message.error(response.data.resultMsg);
          }
        }).catch((response) => {
          console.log(response)
        })
      }
    },
  }
}
</script>

<style lang="less" scoped>
.content-cotainer {
  padding: 20px;
  width: 50%;
  height: 100%;
}
</style>